home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / cinemat.c < prev    next >
C/C++ Source or Header  |  2000-05-13  |  11KB  |  376 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Generic functions used by the Cinematronics Vector games
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vector.h"
  11. #include "cpu/ccpu/ccpu.h"
  12.  
  13. #define VEC_SHIFT 16
  14.  
  15. #define RED   0x04
  16. #define GREEN 0x02
  17. #define BLUE  0x01
  18. #define WHITE RED|GREEN|BLUE
  19.  
  20. static int cinemat_monitor_type;
  21. static int cinemat_overlay_req;
  22. static int cinemat_backdrop_req;
  23. static int cinemat_screenh;
  24. static struct artwork_element *cinemat_simple_overlay;
  25.  
  26. static int color_display;
  27. static struct artwork *spacewar_panel;
  28. static struct artwork *spacewar_pressed_panel;
  29.  
  30. struct artwork_element starcas_overlay[]=
  31. {
  32.     {{ 0, 400-1, 0, 300-1},0x00,  61,  0xff, OVERLAY_DEFAULT_OPACITY},
  33.     {{ 200, 49, 150, -2},  0xff, 0x20, 0x20, OVERLAY_DEFAULT_OPACITY},
  34.     {{ 200, 29, 150, -2},  0xff, 0xff, 0xff, OVERLAY_DEFAULT_OPACITY}, /* punch hole in outer circle */
  35.     {{ 200, 38, 150, -1},  0xe0, 0xff, 0x00, OVERLAY_DEFAULT_OPACITY},
  36.     {{-1,-1,-1,-1},0,0,0,0}
  37. };
  38.  
  39. struct artwork_element tailg_overlay[]=
  40. {
  41.     {{0, 400-1, 0, 300-1}, 0, 64, 64, OVERLAY_DEFAULT_OPACITY},
  42.     {{-1,-1,-1,-1},0,0,0,0}
  43. };
  44.  
  45. struct artwork_element sundance_overlay[]=
  46. {
  47.     {{0, 400-1, 0, 300-1}, 0xff, 0xff, 0x20, OVERLAY_DEFAULT_OPACITY},
  48.     {{-1,-1,-1,-1},0,0,0,0}
  49. };
  50.  
  51. struct artwork_element solarq_overlay[]=
  52. {
  53.     {{0, 400-1, 30, 300-1},0x20, 0x20, 0xff, OVERLAY_DEFAULT_OPACITY},
  54.     {{ 0,  399, 0,    29}, 0xff, 0x20, 0x20, OVERLAY_DEFAULT_OPACITY},
  55.     {{ 200, 12, 150,  -2}, 0xff, 0xff, 0x20, OVERLAY_DEFAULT_OPACITY},
  56.     {{-1,-1,-1,-1},0,0,0,0}
  57. };
  58.  
  59.  
  60. void CinemaVectorData (int fromx, int fromy, int tox, int toy, int color)
  61. {
  62.     static int lastx, lasty;
  63.  
  64.     fromy = cinemat_screenh - fromy;
  65.     toy = cinemat_screenh - toy;
  66.  
  67.     if (fromx != lastx || fromx != lasty)
  68.         vector_add_point (fromx << VEC_SHIFT, fromy << VEC_SHIFT, 0, 0);
  69.  
  70.     if (color_display)
  71.         vector_add_point (tox << VEC_SHIFT, toy << VEC_SHIFT, color & 0x07, color & 0x08 ? 0x80: 0x40);
  72.     else
  73.         vector_add_point (tox << VEC_SHIFT, toy << VEC_SHIFT, WHITE, color * 12);
  74.  
  75.     lastx = tox;
  76.     lasty = toy;
  77. }
  78.  
  79. /* This is called by the game specific init function and sets the local
  80.  * parameters for the generic function cinemat_init_colors() */
  81. void cinemat_select_artwork (int monitor_type, int overlay_req, int backdrop_req, struct artwork_element *simple_overlay)
  82. {
  83.     cinemat_monitor_type = monitor_type;
  84.     cinemat_overlay_req = overlay_req;
  85.     cinemat_backdrop_req = backdrop_req;
  86.     cinemat_simple_overlay = simple_overlay;
  87. }
  88.  
  89. static void shade_fill (unsigned char *palette, int rgb, int start_index, int end_index, int start_inten, int end_inten)
  90. {
  91.     int i, inten, index_range, inten_range;
  92.  
  93.     index_range = end_index-start_index;
  94.     inten_range = end_inten-start_inten;
  95.     for (i = start_index; i <= end_index; i++)
  96.     {
  97.         inten = start_inten + (inten_range) * (i-start_index) / (index_range);
  98.         palette[3*i  ] = (rgb & RED  )? inten : 0;
  99.         palette[3*i+1] = (rgb & GREEN)? inten : 0;
  100.         palette[3*i+2] = (rgb & BLUE )? inten : 0;
  101.     }
  102. }
  103.  
  104.  
  105. void cinemat_init_colors (unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  106. {
  107.     int i,j,k, nextcol;
  108.     char filename[1024];
  109.  
  110.     int trcl1[] = { 0,0,2,2,1,1 };
  111.     int trcl2[] = { 1,2,0,1,0,2 };
  112.     int trcl3[] = { 2,1,1,0,2,0 };
  113.  
  114.     /* initialize the first 8 colors with the basic colors */
  115.     for (i = 0; i < 8; i++)
  116.     {
  117.         palette[3*i  ] = (i & RED  ) ? 0xff : 0;
  118.         palette[3*i+1] = (i & GREEN) ? 0xff : 0;
  119.         palette[3*i+2] = (i & BLUE ) ? 0xff : 0;
  120.     }
  121.  
  122.     shade_fill (palette, WHITE, 8, 23, 0, 255);
  123.     nextcol = 24;
  124.  
  125.     /* fill the rest of the 256 color entries depending on the game */
  126.     switch (cinemat_monitor_type)
  127.     {
  128.         case  CCPU_MONITOR_BILEV:
  129.         case  CCPU_MONITOR_16LEV:
  130.             color_display = FALSE;
  131.             /* Attempt to load backdrop if requested */
  132.             if (cinemat_backdrop_req)
  133.             {
  134.                 sprintf (filename, "%sb.png", Machine->gamedrv->name );
  135.                 backdrop_load(filename, nextcol, Machine->drv->total_colors-nextcol);
  136.                 if (artwork_backdrop!=NULL)
  137.                 {
  138.                     memcpy (palette+3*artwork_backdrop->start_pen, artwork_backdrop->orig_palette, 3*artwork_backdrop->num_pens_used);
  139.                     if (Machine->scrbitmap->depth == 8)
  140.                         nextcol += artwork_backdrop->num_pens_used;
  141.                 }
  142.             }
  143.             /* Attempt to load overlay if requested */
  144.             if (cinemat_overlay_req)
  145.             {
  146.                 if (cinemat_simple_overlay != NULL)
  147.                 {
  148.                     /* use simple overlay */
  149.                     artwork_elements_scale(cinemat_simple_overlay,
  150.                                            Machine->scrbitmap->width,
  151.                                            Machine->scrbitmap->height);
  152.                     overlay_create(cinemat_simple_overlay, nextcol,Machine->drv->total_colors-nextcol);
  153.                 }
  154.                 else
  155.                 {
  156.                     /* load overlay from file */
  157.                     sprintf (filename, "%so.png", Machine->gamedrv->name );
  158.                     overlay_load(filename, nextcol, Machine->drv->total_colors-nextcol);
  159.                 }
  160.  
  161.                 if ((Machine->scrbitmap->depth == 8) || (artwork_backdrop == 0))
  162.                     overlay_set_palette (palette, (Machine->drv->total_colors > 256 ? 256 : Machine->drv->total_colors) - nextcol);
  163.             }
  164.             break;
  165.  
  166.         case  CCPU_MONITOR_WOWCOL:
  167.             color_display = TRUE;
  168.             /* TODO: support real color */
  169.             /* put in 40 shades for red, blue and magenta */
  170.             shade_fill (palette, RED       ,   8,  47, 10, 250);
  171.             shade_fill (palette, BLUE      ,  48,  87, 10, 250);
  172.             shade_fill (palette, RED|BLUE  ,  88, 127, 10, 250);
  173.  
  174.             /* put in 20 shades for yellow and green */
  175.             shade_fill (palette, GREEN     , 128, 147, 10, 250);
  176.             shade_fill (palette, RED|GREEN , 148, 167, 10, 250);
  177.  
  178.             /* and 14 shades for cyan and white */
  179.             shade_fill (palette, BLUE|GREEN, 168, 181, 10, 250);
  180.             shade_fill (palette, WHITE     , 182, 194, 10, 250);
  181.  
  182.             /* Fill in unused gaps with more anti-aliasing colors. */
  183.             /* There are 60 slots available.           .ac JAN2498 */
  184.             i=195;
  185.             for (j=0; j<6; j++)
  186.             {
  187.                 for (k=7; k<=16; k++)
  188.                 {
  189.                     palette[3*i+trcl1[j]] = ((256*k)/16)-1;
  190.                     palette[3*i+trcl2[j]] = ((128*k)/16)-1;
  191.                     palette[3*i+trcl3[j]] = 0;
  192.                     i++;
  193.                 }
  194.             }
  195.             break;
  196.     }
  197. }
  198.  
  199.  
  200. void spacewar_init_colors (unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  201. {
  202.     int width, height, i, nextcol;
  203.  
  204.     color_display = FALSE;
  205.  
  206.     /* initialize the first 8 colors with the basic colors */
  207.     for (i = 0; i < 8; i++)
  208.     {
  209.         palette[3*i  ] = (i & RED  ) ? 0xff : 0;
  210.         palette[3*i+1] = (i & GREEN) ? 0xff : 0;
  211.         palette[3*i+2] = (i & BLUE ) ? 0xff : 0;
  212.     }
  213.  
  214.     for (i = 0; i < 16; i++)
  215.         palette[3*(i+8)]=palette[3*(i+8)+1]=palette[3*(i+8)+2]= (255*i)/15;
  216.  
  217.     spacewar_pressed_panel = NULL;
  218.     width = Machine->scrbitmap->width;
  219.     height = 0.16 * width;
  220.  
  221.     nextcol = 24;
  222.  
  223.     artwork_load_size(&spacewar_panel, "spacewr1.png", nextcol, Machine->drv->total_colors - nextcol, width, height);
  224.     if (spacewar_panel != NULL)
  225.     {
  226.         if (Machine->scrbitmap->depth == 8)
  227.             nextcol += spacewar_panel->num_pens_used;
  228.  
  229.         artwork_load_size(&spacewar_pressed_panel, "spacewr2.png", nextcol, Machine->drv->total_colors - nextcol, width, height);
  230.         if (spacewar_pressed_panel == NULL)
  231.         {
  232.             artwork_free (&spacewar_panel);
  233.             return ;
  234.         }
  235.     }
  236.     else
  237.         return;
  238.  
  239.     memcpy (palette+3*spacewar_panel->start_pen, spacewar_panel->orig_palette,
  240.             3*spacewar_panel->num_pens_used);
  241.  
  242.     if (Machine->scrbitmap->depth == 8)
  243.         memcpy (palette+3*spacewar_pressed_panel->start_pen, spacewar_pressed_panel->orig_palette,
  244.                 3*spacewar_pressed_panel->num_pens_used);
  245. }
  246.  
  247. /***************************************************************************
  248.  
  249.   Start the video hardware emulation.
  250.  
  251. ***************************************************************************/
  252.  
  253. int cinemat_vh_start (void)
  254. {
  255.     vector_set_shift (VEC_SHIFT);
  256.  
  257.     if (artwork_backdrop)
  258.     {
  259.         backdrop_refresh (artwork_backdrop);
  260.         backdrop_refresh_tables (artwork_backdrop);
  261.     }
  262.  
  263.     cinemat_screenh = Machine->drv->visible_area.max_y - Machine->drv->visible_area.min_y;
  264.     return vector_vh_start();
  265. }
  266.  
  267. int spacewar_vh_start (void)
  268. {
  269.     vector_set_shift (VEC_SHIFT);
  270.     if (spacewar_panel) backdrop_refresh(spacewar_panel);
  271.     if (spacewar_pressed_panel) backdrop_refresh(spacewar_pressed_panel);
  272.     cinemat_screenh = Machine->drv->visible_area.max_y - Machine->drv->visible_area.min_y;
  273.     return vector_vh_start();
  274. }
  275.  
  276.  
  277. void cinemat_vh_stop (void)
  278. {
  279.     vector_vh_stop();
  280. }
  281.  
  282. void spacewar_vh_stop (void)
  283. {
  284.     if (spacewar_panel != NULL)
  285.         artwork_free(&spacewar_panel);
  286.  
  287.     if (spacewar_pressed_panel != NULL)
  288.         artwork_free(&spacewar_pressed_panel);
  289.  
  290.     vector_vh_stop();
  291. }
  292.  
  293. void cinemat_vh_screenrefresh (struct osd_bitmap *bitmap, int full_refresh)
  294. {
  295.     vector_vh_screenrefresh(bitmap, full_refresh);
  296.     vector_clear_list ();
  297. }
  298.  
  299. void spacewar_vh_screenrefresh (struct osd_bitmap *bitmap, int full_refresh)
  300. {
  301.     int tk[] = {3, 8, 4, 9, 1, 6, 2, 7, 5, 0};
  302.     int i, pwidth, pheight, key, row, col, sw_option;
  303.     float scale;
  304.     struct osd_bitmap vector_bitmap;
  305.     struct rectangle rect;
  306.  
  307.     static int sw_option_change;
  308.  
  309.     if (spacewar_panel == NULL)
  310.     {
  311.         vector_vh_screenrefresh(bitmap, full_refresh);
  312.         vector_clear_list ();
  313.         return;
  314.     }
  315.  
  316.     pwidth = spacewar_panel->artwork->width;
  317.     pheight = spacewar_panel->artwork->height;
  318.  
  319.     vector_bitmap.width = bitmap->width;
  320.     vector_bitmap.height = bitmap->height - pheight;
  321.     vector_bitmap._private = bitmap->_private;
  322.     vector_bitmap.line = bitmap->line;
  323.  
  324.     vector_vh_screenrefresh(&vector_bitmap,full_refresh);
  325.     vector_clear_list ();
  326.  
  327.     if (full_refresh)
  328.         copybitmap(bitmap,spacewar_panel->artwork,0,0,
  329.                    0,bitmap->height - pheight, 0,TRANSPARENCY_NONE,0);
  330.  
  331.     scale = pwidth/1024.0;
  332.  
  333.     sw_option = input_port_1_r(0);
  334.  
  335.     /* move bits 10-11 to position 8-9, so we can just use a simple 'for' loop */
  336.     sw_option = (sw_option & 0xff) | ((sw_option >> 2) & 0x0300);
  337.  
  338.     sw_option_change ^= sw_option;
  339.  
  340.     for (i = 0; i < 10; i++)
  341.     {
  342.         if (sw_option_change & (1 << i) || full_refresh)
  343.         {
  344.             key = tk[i];
  345.             col = key % 5;
  346.             row = key / 5;
  347.             rect.min_x = scale * (465 + 20 * col);
  348.             rect.max_x = scale * (465 + 20 * col + 18);
  349.             rect.min_y = scale * (39  + 20 * row) + vector_bitmap.height;
  350.             rect.max_y = scale * (39  + 20 * row + 18) + vector_bitmap.height;
  351.  
  352.             if (sw_option & (1 << i))
  353.             {
  354.                 copybitmap(bitmap,spacewar_panel->artwork,0,0,
  355.                            0, vector_bitmap.height, &rect,TRANSPARENCY_NONE,0);
  356.             }
  357.             else
  358.             {
  359.                 copybitmap(bitmap,spacewar_pressed_panel->artwork,0,0,
  360.                            0, vector_bitmap.height, &rect,TRANSPARENCY_NONE,0);
  361.             }
  362.  
  363.             osd_mark_dirty (rect.min_x, rect.min_y,
  364.                             rect.max_x, rect.max_y, 0);
  365.         }
  366.     }
  367.     sw_option_change = sw_option;
  368. }
  369.  
  370. int cinemat_clear_list(void)
  371. {
  372.     if (osd_skip_this_frame())
  373.         vector_clear_list ();
  374.     return ignore_interrupt();
  375. }
  376.